package org.turbobytes.unikey.util.db.metadata;

import org.turbobytes.unikey.util.db.model.Column;
import org.turbobytes.unikey.util.db.model.DataType;

import java.sql.Connection;
import java.util.List;
import java.util.Map;

/**
 * Common interface for all database dialects
 * Will primarily expose methods for all the database metadata related operations needed by unikey
 *
 * @author Ganeshji Marwaha
 * @since Aug 7, 2010
 */
public interface Metadata {
  /**
   * Retrieve a list of all the table names for the database represented by the connection
   * @param connection - to talk to the database
   * @return a list of table names
   */
  public List<String> getTableNames(Connection connection);

  /**
   * Checks whether a given table is present within the database represented by the connection
   * @param connection - to talk to the database
   * @param tableName - table name to check
   * @return whether the table is present in the database or not
   */
  public boolean isTablePresent(Connection connection, String tableName);

  /**
   * Retrieve a list of all the column names for the given tableName
   * @param connection - to talk to the database
   * @param tableName - table name to get the columns for
   * @return a list of column names belonging to the table specified by {@code tableName}
   */
  public Map<String, Column> getColumnNames(Connection connection, String tableName);

  /**
   * Returns a fully populated Column object given the name
   * @param connection - to talk to the database
   * @param tableName - to get the column from
   * @param columnName - to get the column details for
   * @return a {@code Column} instance with column name and its type. Returns null if column name is not present
   *         in the table
   */
  public Column getColumn(Connection connection, String tableName, String columnName);

  /**
   * Checks whether a given column in present with the given table.
   * @param connection - to talk to the database
   * @param tableName - to check for the column
   * @param columnName - to check for existence
   * @return whether the column exists in the given {@code tableName} or not
   */
  public boolean isColumnPresent(Connection connection, String tableName, String columnName);

  /**
   * Get the supported data types for the specified  dialect.
   * @param dataType - the app data type to retrieve the corresponding db data types
   * @return a list of string representing the supported db data types
   */
  public List<String> getSupportedDbDataTypes(DataType dataType);

}
